package com.mobileares.midp.demo.client.page;

import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.mobileares.midp.widgets.client.textbox2.ListBoxLabel;
import com.mobileares.midp.widgets.client.textbox2.TextBoxLabel;
import com.mobileares.midp.widgets.client.textbox2.widget.TreeListBox;
import com.mobileares.midp.widgets.client.tree.CTreeItem;
import com.mobileares.midp.widgets.client.utils.CodeModel;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-7-22
 * Time: 17:36:39
 * To change this template use File | Settings | File Templates.
 */
public class Form extends Composite {
    private FlowPanel container;

    public Form() {
        container = new FlowPanel();
        initWidget(container);
        initForm();
    }

    private void initForm() {
        FlowPanel flow = new FlowPanel();
        final TextBoxLabel name = new TextBoxLabel("登录名");
        name.setAlertSign();
        name.showTipMessage("唯一性的标示");
        name.getLabelWidget().addBlurHandler(new BlurHandler() {
            public void onBlur(BlurEvent event) {
                if (name.getValue() == null)
                    name.showErrorMessage("不能为空！");
            }
        });
        name.getLabelWidget().addFocusHandler(new FocusHandler() {
            public void onFocus(FocusEvent event) {
                name.reset();
            }
        });
        TextBoxLabel age = new TextBoxLabel("年龄");
        TextBoxLabel address = new TextBoxLabel("家庭地址");
        ListBoxLabel sex = new ListBoxLabel("性别");
        initSex(sex);
        sex.setAlertSign();
        sex.setValue(null);

        flow.add(name);
        flow.add(age);
        flow.add(address);
        flow.add(sex);
        container.add(flow);
        testTreeListBox();
    }

    private void initSex(ListBoxLabel w) {
        w.getLabelWidget().addItem("请选择", "");
        w.getLabelWidget().addItem("男", "1");
        w.getLabelWidget().addItem("女", "0");
        w.getLabelWidget().addItem("非", "3");
        w.getLabelWidget().addItem("非", "3");
        w.getLabelWidget().addItem("非", "3");
        w.getLabelWidget().addItem("非", "3");
        w.getLabelWidget().addItem("非", "3");
        w.getLabelWidget().addItem("非", "3");
    }
    private void testTreeListBox(){
        TreeListBox box = new TreeListBox();
        box.addItem(new CodeModel("北京","bj"));
        CTreeItem item = box.addItem(new CodeModel("天津","tj"));
        box.addItem(item,new CodeModel("宁河","nh"));
        box.addItem(item,new CodeModel("汉沽","hg"));
        box.addItem(item,new CodeModel("塘沽","tg"));

        container.add(box);

    }


}
